{extends file='../base.html'}

{block name=content}
<div class="steps">
    <ul class="grid">
        <li class="current">
            <span class="step">1</span>检测环境
        </li>
        <li>
            <span class="step">2</span>创建数据
        </li>
        <li>
            <span class="step">3</span>完成安装
        </li>
    </ul>
</div>
<div class="server">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <th width="25%">环境检测</th>
            <th width="25%">推荐配置</th>
            <th width="25%">当前状态</th>
            <th>最低要求</th>
        </tr>
        {foreach $env as $item}
        {if isset($item.is_title)}
        <tr>
            <th width="100%" colspan="4">{$item.title}</th>
        </tr>
        {continue}
        {/if}
        <tr {if isset($item.id)}id="{$item.id}"{/if}>
            <td>{$item[1]}
                {if isset($item.link)}
                <a href="{$item.link}" target="_blank"><i class="fa fa-question-circle"></i></a>
                {/if}
            </td>
            <td>{$item[2]}</td>
            <td>
            {if $item[3]}
            <i class="fa fa-check"></i>
            {else}
            <i class="fa fa-remove"></i>
            {/if}
            {$item[4]}</td>
            <td>{$item[5]}</td>
        </tr>
        {/foreach}        
    </table>
    
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <th width="50%">目录、文件权限检查</th>
            <th>写入</th>
            <th>读取</th>
        </tr>
        {foreach $fresult as $dir => $item}        
        <tr {if isset($item.id)}id="{$item.id}"{/if}>
            <td>{$dir}</td>
            <td>{if $item.w}<i class="fa fa-check"></i> 可写{else}<i class="fa fa-remove"></i> 不可写{/if}</td>            
            <td>{if $item.r}<i class="fa fa-check"></i> 可读{else}<i class="fa fa-remove"></i> 不可读{/if}</td>        
        </tr>
        {/foreach}        
    </table>
    
</div>



<div class="bottom-btns">
    <a href="{$absroot}?s=install/index/step2" class="layui-btn">重新检测</a><a href="{url('install/index/step3')}" class="layui-btn" onclick="return checkError()">下一步 >></a>
</div>

<script>
var error_count = {$error_count+1};
$.ajax({
    url: "{url('install/Index/testRewrite')}",
    type: 'GET',
    dataType: 'JSON',
    success: function (data) {
        if (data.result == 'success') {
            error_count--;
            $('#rewrite').find('td:eq(2)').html('<i class="fa fa-check"></i> 已开启');
        } else {
            $('#rewrite').find('td:eq(2)').html('<i class="fa fa-remove"></i> 失败console中查看');
            console.log('URL重写开启，但路由解析失败；手动访问“{url("install/Index/testRewrite")}”分析失败原因');
        }
        
    },
    error: function () {
        $('#rewrite').find('td:eq(2)').html('<i class="fa fa-remove"></i> 未开启');
    }
})

function checkError()
{
    if (error_count > 0) {
        layui.use('layer', function(){
          var layer = layui.layer;
          
          layer.alert('请先处理检测不通过的环境', {
             icon : 2
          });
        });              
        return false;
    } else {
        return true;
    }
}
</script>
{/block}